package com.example.smartcity_poverty.ui.AllService.StopWhere.adapter

import android.content.Intent
import com.example.smartcity_poverty.App.Companion.url
import com.example.smartcity_poverty.Base.BaseRecyclerAdapter
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.logic.model.stop.StopWhereAll
import com.example.smartcity_poverty.ui.AllService.StopWhere.StopWhereShowAllActivity
import kotlinx.android.synthetic.main.re_stop_list.*

/**
 *  created by ikun
 *  ANDROID STUDIO - version 4.0
 *  email: jinkunwei41@gmail.com
 * --------------------------------
 *  停车场列表适配器
 **/
class StopListAdapter(
    val list: MutableList<StopWhereAll.RowsBean>,
    val layoutId: Int
) : BaseRecyclerAdapter<StopWhereAll.RowsBean>(list, layoutId){
    override fun setData(
        view: BaseViewHolder.ViewFind,
        data: StopWhereAll.RowsBean,
        position: Int,
        holder: BaseViewHolder
    ) {
        if (list.size <= 0){

        }else{
            list.sortBy { it -> it.distance }

            val d = list[position]
            val v = holder.viewFind
            val con = holder.viewFind.view?.context

            // 服务器地址访问不了图片
            // glide(url + d.imgUrl, holder.viewFind.stopImage)
            v.stopImage.setImageResource(R.mipmap.stop1)
            v.stopName.text = d.parkName
            v.stopThis.text = "地址: ${d.address}"
            v.stopThisThis.text = "距离你${d.distance}米"
            v.stopDao.text = "收费${d.rates}$"
            v.stopSize.text = "剩余${d.vacancy}停车位"

            holder.itemView.setOnClickListener {
                con?.startActivity(Intent(con, StopWhereShowAllActivity::class.java).apply {
                    putExtra("image", url + d.imgUrl.toString())
                    putExtra("title", v.stopName.text.toString())
                    putExtra("this", v.stopThis.text.toString())
                    putExtra("ThisThis", v.stopThisThis.text.toString())
                    putExtra("dao", d.rates.toString())
                    putExtra("Size", v.stopSize.text.toString())
                })
            }
        }


    }

}